package com.service.impl;

import com.bean.entity.TestDetail;
import com.bean.pojo.PageAssistant;
import com.bean.vo.TestDetailVo;
import com.dao.TestDetailMapper;
import com.service.TestDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
@Service
public class TestDetailServiceImpl implements TestDetailService {
    @Autowired
    private TestDetailMapper testDetailMapper;
    @Override
    public int save(TestDetail t) throws Exception {
        int insert = testDetailMapper.insert(t);
        if (insert==1) return 1;
        throw new Exception("试卷详情增加失败！");
    }

    @Override
    public int remove(TestDetail t) throws Exception {
        int delete = testDetailMapper.delete(t);
        if (delete==1) return 1;
        throw new Exception("试卷详情删除成功！");
    }

    @Override
    public int modify(TestDetail t) throws Exception {
        int update = testDetailMapper.update(t);
        if (update==1) return 1;
        throw new Exception("试卷详情修改成功！");
    }

    @Override
    public TestDetailVo unique(TestDetail t) throws Exception {
        List<TestDetailVo> testDetailVoList = testDetailMapper.select(t);
        if (testDetailVoList.size()!=1) throw new Exception("试卷信息查询失败！");
        return testDetailVoList.get(0);
    }

    @Override
    public List<TestDetailVo> query(TestDetail t) {
        return testDetailMapper.select(t);
    }

    @Override
    public PageAssistant<TestDetailVo> queryByPage(Map<String, Object> map, PageAssistant<TestDetailVo> pa) {

        //查询并设置总记录数
        pa.setCount(testDetailMapper.selectCount(map));

        //添加分页参数
        map.put("startCode",pa.getStartCode());
        map.put("pageSize",pa.getPageSize());

        //查询并设置页面内容
        pa.setItems(testDetailMapper.selectByPage(map));
        return pa;
    }
}
